<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>绩效考核-满意度</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="static/css/font.css">
    <link rel="stylesheet" href="static/css/xadmin.css">
    <script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="static/lib/layui/layui.js"></script>
    <script type="text/javascript" src="static/js/xadmin.js"></script>
</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
		<span class="layui-breadcrumb"> <a>首页</a> <a>民主测评</a> <a> <cite>满意度评分</cite></a>
		</span> <a class="layui-btn layui-btn-small"
                   style="line-height: 1.6em; margin-top: 3px; float: right"
                   href="javascript:location.replace(location.href);" title="刷新"> <i
        class="layui-icon" style="line-height: 30px">ဂ</i></a>
</div>
<div class="x-body" id="container">
    <div class="demoTable">
        部门ID：
        <div class="layui-inline">
            <input type="number" id="d_id" name="d_id" required
                   lay-verify="number" autocomplete="off" class="layui-input" value=""/>
        </div>
        员工号：
        <div class="layui-inline">
            <input type="text" id="e_id" name="e_id" required
                   lay-verify="number" autocomplete="off" class="layui-input" value=""/>
        </div>
        员工姓名：
        <div class="layui-inline">
            <input type="text" id="e_name" name="e_name" required autocomplete="off" class="layui-input" value=""/>
        </div>
        <button class="layui-btn" data-type="reload">查&nbsp;&nbsp;询</button>
    </div>
    <div style="text-align: center">
        <div class="demoTable">（*请填入加分分数*）</div>
        <table id="demo" class="layui-table" lay-filter="demo"></table>
    </div>
    <div class="layui-inline">
        <a class="layui-btn layui-btn-danger batchUnlock" id="sbmt">
            <i class="layui-icon layui-icon-key"></i>提交</a>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'table', 'util'], function () {
        var laydate = layui.laydate
            , table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , height: 'full'
            , url: 'employeeSatisfaction.do'
            , page: false
            , method: "post"
            , initSort: {field: 'did', type: 'desc'}
            , id: 'demo'
            , cols: [[ //表头
                {field: 'did', rowspan: 2, title: '部门ID', align: 'center', fixed: 'left'}
                , {field: 'dName', rowspan: 2, title: '部门名称', align: 'center', fixed: 'left'}
                , {field: 'eAccount', rowspan: 2, title: '工号', align: 'center', fixed: 'left'}
                , {field: 'eName', rowspan: 2, title: '姓名', align: 'center', fixed: 'left'}
                , {field: 'gScore', rowspan: 2, title: '满意度评分', align: 'center', edit: 'number'}
                , {field: 'gRmk', rowspan: 2, title: '加分原因', align: 'center', edit: 'text'}
            ]]
        });

        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('demo', {
                    where: {
                        d_id: $("#d_id").val(),
                        e_id: $("#e_id").val(),
                        e_name: $("#e_name").val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            console.log(type);
            active[type] ? active[type].call(this) : '';
        });

        //批量提交  使用封装后的ajax
        $("#sbmt").click(function () {
            const list = table.cache['demo'];
            var len = list.length;
            var flg = "0";
            let reg = /^\d+$/g;
            for (var i = 0; i < len; i++) {
                delete list[i].LAY_TABLE_INDEX;
                var ttv = list[i].gScore
                /**
                 if (ttv != reg) {
					var flg = "1";
					layer.msg('输入整数分数', {
				        time: 20000, //20s后自动关闭
				        btn: '明白了'
				    });
					break;
				}**/
            }
            if (flg == '0') {
                console.log(list);
                console.log("list=" + JSON.stringify(list));
                $.ajax({
                    type: 'post',
                    url: 'updateSatisfaction.do',
                    data: "list=" + JSON.stringify(list),
                    dataType: 'json',
                    success: function (result) {
                        if (result.code == 0) {
                            layer.msg(result.msg);
                            table.reload('demo', {
                                where: {
                                    d_id: $("#d_id").val(),
                                    e_id: $("#e_id").val(),
									e_name: $("#e_name").val()
                                }
                            });
                        } else {
                            layer.msg(result.msg);
                        }
                    }
                });
            }
        });

        //监听单元格编辑
        table.on('edit(demo)', function (obj) {
            var ttv = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
            console.log(obj.data);
            let reg = /^\d+$/g;
            if (ttv != reg) {
                /**
                 layer.msg('请输入整数分数', {
			        time: 20000 //20s后自动关闭
			        ,btn: '明白了'
			        ,btnAlign: 'c' //按钮居中
			    });

                 添加禁用按钮样式
                 $("#sbmt").addClass("layui-btn-disabled");
                 //真正禁用按钮的语句
                 $("#sbmt").attr("disabled", true);
                 **/
            }
            /**
             else {
				//去除禁用样式
				$("#sbmt").removeClass("layui-btn-disabled");
				//解除禁用的语句
				$("#sbmt").attr("disabled", false);
			}
             **/
        });

    });
</script>
</html>
